<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 

%>
<!DOCTYPE HTML>  
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>编辑视频</title>
	<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="bootstrap-table/dist/bootstrap-table.css">
    <link rel="stylesheet" type="text/css" href="css/xcConfirm.css" />
	<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />
	<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
	<link rel="stylesheet" href="bootstrap-fileinput-master/css/fileinput.min.css">
	<link href="umeditor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/x-admin.css">
    <link href="http://jssdk.demo.qiniu.io/images/favicon.ico" rel="shortcut icon">
    <script src="js/plupload.full.min.js"></script>
    <script src="js/common2.js"></script>
    <script type="text/javascript" src="http://jssdk.demo.qiniu.io/dist/qiniu.min.js"></script>
    
    <style type="text/css">
        #panel {
            position: absolute;
            background-color: white;
            max-height: 90%;
            overflow-y: auto;
            top: 10px;
            right: 10px;
            width: 280px;
        }
        .td1{
			float:left;
			width:50px;
			display: block; 
			valign:middle;
		}
		.td2{
			float:left;
			width:200px;
			display: block; 
			valign:middle;
		}
		.td3{
			float:left;
			width:660px;
			display: block; 
			valign:middle;
		}
    </style>
</head>
<body>
	<div class="x-body">
            <div   class="form-horizontal" role="form">

			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">视频标题:</label>
			    <div class="col-sm-3">
			      <input type="text" class="form-control" id="title" name="title" value="${result.G_LESSON_NAME}" placeholder="请输入视频标题"/>
			      <input type="hidden" id="G_ID" name="G_ID" value="${result.G_ID}"/>
			    </div>
			  </div>
			  
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">视频金额(如果金额为0则积分也为0):</label>
			    <div class="col-sm-3">
                      <input class="form-control" placeholder="请输入价格" value="${result.G_LESSON_MONEY}" id="G_LESSON_MONEY">
                </div>
			  </div>
			  
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">是否积分购买:</label>
			    <div class="col-sm-3">
                      <input class="form-control" placeholder="如果是请输入积分，否则请输0" value="${result.G_LESSON_INTEGEAL}" id="G_LESSON_INTEGEAL">
                </div>
			  </div>
			  
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">可得积分:</label>
			     <div class="col-sm-3">
                      <input class="form-control" placeholder="无" value="${result.get_integral}" id="get_integral">
                    </div>
			  </div>
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">可得成长值:</label>
			     <div class="col-sm-3">
                      <input class="form-control" placeholder="无" value="${result.get_growth_value}" id="get_growth_value">
                    </div>
			  </div>
			   <div class="form-group">
			   <label for="firstname" class="col-sm-2 control-label">视频讲师(默认保存之前讲师):</label>
			    <div class="col-sm-3">
			      <select id="teacher_name" class="form-control">
              	  </select>
			    </div>
			   </div> 
			    <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">视频简介:</label>
			     <div class="col-sm-3">
                      <input class="form-control" placeholder="无" value="${result.content}" id="content">
                    </div>
			  </div>
			   <div class="form-group">
	    			<div class="col-sm-3" style="top:530px;height:200px;" id="container">
		        		<button class="btn btn-info"  id="pickfiles">请选择视频文件</button>
		    			<button class="btn btn-info"  id="uploadfiles">上传</button>
		    			<p id="text1"></p>
		        		<!-- <ul id="file-list">
		        		</ul> -->
		        		<br>
		        		<input type="text" class="form-control" id="key" name="key" disabled="disabled" placeholder="文件名称"/>
		        		<br>
		        		<input type="hidden" class="form-control" id="size" name="size" disabled="disabled" placeholder="文件大小"/>
		        		<input type="text" class="form-control" id="url" name="url" disabled="disabled" placeholder="文件路径"/>
		    		</div>
    			</div>
			</div>
          </div>
        			<button type="button" style="margin-left:30%;margin-top:150px;" onclick="save()"  class="btn btn-info" >保存</button>
        			<button type="reset" style="margin-top:150px;" onclick="cancel()"  class="btn btn-info" >取消 </button>
        <script src="lib/layui/layui.js" charset="utf-8"></script>
        <script src="js/x-layui.js" charset="utf-8"></script>
        <!-- 加载需要的js -->
		<script src="js/jquery-3.2.1.min.js"></script>
		<script src="js/common2.js"></script>
		<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="js/jquery-bootstrap-pagination.js"></script>
		<script src="js/qunit-1.11.0.js"></script>
		<script src="js/bootstrap-datetimepicker.js"></script>
		<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	    <script src="js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
	    <script src="bootstrap-fileinput-master/js/fileinput.min.js"></script>
		<script src="bootstrap-fileinput-master/js/locales/zh.js"></script>
		
		<script type="text/javascript" src="umeditor/third-party/template.min.js"></script>
    	<script type="text/javascript" charset="utf-8" src="umeditor/umeditor.config.js"></script>
    	<script type="text/javascript" charset="utf-8" src="umeditor/umeditor.min.js"></script>
    	<script type="text/javascript" src="umeditor/lang/zh-cn/zh-cn.js"></script>
        <script>
        $(function(){
       		$.ajax({
    	        type: "get",
    	        url: "courseInfo/selectTeacherList",
    	        dataType:"json",
    	        success: function(data){    
    	      	  if(data.code==200){	           	              
    	      		var htm='';
    	      		    htm +='<option value="">请选择视频讲师</option>';
    	     		for (var i = 0; i < data.data.length; i++) {
    	   				var bean = data.data;
    	   				htm +='<option value="'+bean[i].G_ID+'">'+bean[i].G_NAME+'</option>';
    				}
    	     		$("#teacher_name").html(htm);
    	   	 	  }
    	 	      
    	        }
    	    });
       	   });
        
        $("#title").change(function(){
        	var G_LESSON_NAME = $("#title").val();
        	$.ajax({
    	        type: "get",
    	        url: "video/selectVideoName",
    	        data:{
    	        	G_LESSON_NAME:G_LESSON_NAME,
    	        },
    	        dataType:"json",
    	        success: function(data){    
    	      	  if(data.code == 100){	           	              
    	      		var txt = data.msg;
    	      	    layer.alert(txt); 
    	      	  	$("#title").val("")
    	   	 	  }
    	        }
    	    });
        })
        
         $("#G_LESSON_MONEY").change(function(){
	    	var v1 = $("#G_LESSON_MONEY").val();
	    	if(v1 == 0){
	    		$("#G_LESSON_INTEGEAL").val("0");
	    	}
	    })
        
            layui.use(['form','layer','upload'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
              });
            
          //时间插件
    		$('.form_date').datetimepicker({
    	        language:  'zh-CN',
    	        weekStart: 1,
    	        todayBtn:  1,
    			autoclose: 1,
    			todayHighlight: 1,
    			startView: 2,
    			minView: 2,
    			forceParse: 0
    	    });
            $("#upload").fileinput({
    		    uploadUrl: "upload/photoImg",
    		    uploadAsync: true,
    		    maxFileCount: 1,
    		    initialPreview: [ 
			    	'<img src="${result.cover}"  id="img"  class="file-preview-image"  width="256px" height="160px" />',
			    	],
//    		    overwriteInitial: ture,
//    			    initialPreview: [ "http://lorempixel.com/800/460/people/1"],
//    			    initialPreviewAsData: true, // identify if you are sending preview data only and not the raw markup
//    			    initialPreviewFileType: 'image', // image is the default and can be overridden in config below
//    			    initialPreviewConfig: [
//    			       {caption: "People-1.jpg", size: 576237, width: "120px", url: "/site/file-delete", key: 1},
//    			    ],
//    			    uploadExtraData: {
//    			        img_key: "1000",
//    			        img_keywords: "happy, places",
//    			    }
    		}).on('fileuploaded', function(event, data, previewId, index) {
    		    var form = data.form, files = data.files, extra = data.extra,
    	        response = data.response, reader = data.reader;
    			if(response.data != null && response.data != ""){
    		    	$("#cover").val(response.data);			
    			}else{
    				alert("图片服务器异常，请重新上传！");
    			}
    		});
            
            function deleteRow(e)
            {
             e=e||event;
             var btn=e.srcElement||e.target;
             btn.parentNode.parentNode.parentNode.removeChild(btn.parentNode.parentNode);
            }
            
            function divClick(){    
    		    
      	       var show="";    
      	       var apm = document.getElementsByName("hasGroup");    
      	       for(var i=0;i<apm.length;i++){    
      	       if(apm[i].checked)    
      	        show = apm[i].value;    
      	       }    
      	         
      	       switch (show){    
      	           case '0':    
      	               document.getElementById("com").style.display="none";    
      	               break;    
      	           default:    
      	               document.getElementById("com").style.display="block";    
      	               break;                                                       
      	       }    
      	}

            
            function save(){
   		   	 var title = $("#title").val();
   		   	 if(title == null||title=="") {
   		   		layer.msg('视频名称不能为空!',{icon:2,time:2000});
   			  return ;
   		   	 }
   		   	 
   		   	 var get_growth_value = $("#get_growth_value").val();
   		   	 if(get_growth_value == null||get_growth_value=="") {
   		   		layer.msg('可得成长值不能为空!',{icon:2,time:2000});
   			  return ;
   		   	 }
   		   	 var get_integral = $("#get_integral").val();
   		   	 if(get_integral == null||get_integral=="") {
   		   		layer.msg('可得积分不能为空!',{icon:2,time:2000});
   			  return ;
   		   	 }
   		   	 var G_LESSON_MONEY = $("#G_LESSON_MONEY").val();
   		   	 if(G_LESSON_MONEY == null||G_LESSON_MONEY=="") {
   		   		layer.msg('视频金额不能为空!',{icon:2,time:2000});
   			  return ;
   		   	 }
   		   	 var G_LESSON_INTEGEAL = $("#G_LESSON_INTEGEAL").val();
   		   	 if(G_LESSON_INTEGEAL == null||G_LESSON_INTEGEAL=="") {
   		   		layer.msg('视频积分不能为空!',{icon:2,time:2000});
   			  return ;
   		   	 }
   		   	 var teacher_id = $("#teacher_name").val();
   		   	 var content = $("#content").val();
   			 var teacher_name = $("#teacher_name option:selected").text();
   			 if(teacher_name == "请选择视频讲师"){
   				teacher_name = null;
   			 }
   			 
   			 var url =	$("#url").val();
   			 var size =	$("#size").val();
   			 var key =	$("#key").val();
       			$.ajax({
       	            url: "video/updateVideo",
       	            type: "post",
       	            data: {
       	            	 G_ID:$("input[name=G_ID]").val(),
       	            	 title:title,
   	   	            	 get_integral:get_integral,
   	   	            	 get_growth_value:get_growth_value,
   	   	            	 url:url,
   	   	            	 G_LESSON_MONEY:G_LESSON_MONEY,
   	   	            	 G_LESSON_INTEGEAL:G_LESSON_INTEGEAL,
   	   	            	 key:key,
   	   	            	 size:size,
   	   	            	 teacher_id:teacher_id,
   	   	            	 teacher_name:teacher_name,
   	   	           		 content:content,
   	   		         },
       	            success: function(data) {
       	            	if(data.code==200){
       		           		layer.alert("编辑成功", {icon: 6},function () {
       		           		location.reload()
       			           		//parent.location.reload();
       		                   	// 获得frame索引
       		                  	//var index = parent.layer.getFrameIndex(window.name);
       		                  	//关闭当前frame
       		                  	//parent.layer.close(index);
       		                    //parent.location.reload();
       	              		});    
       			      	}else{
       			   	      	var txt=data.msg;
       		     	    	layer.alert(txt); 
       		     	    }
       			 	} 
       	        });
   		}
   	   
   	   function cancel(){
   		   	
   		// 获得frame索引
           var index = parent.layer.getFrameIndex(window.name);
           //关闭当前frame
           parent.layer.close(index);
   	         
   			}
   	   
   	   
   	$(function(){
   	 $.ajax({
            type: "get",
            url: "qiniu/uptoken",
            dataType:"json",
            success: function(data){    
          	  if(data.code==200){	           	              
         		$("#tokens").val(data.data);
       	 	  }
     	      
            }
        });
   }); 
   
   function getToken() {
   	$.ajax({
           type: "get",
           url: "qiniu/uptoken",
           dataType:"json",
           success: function(data){    
          	
         	  if(data.code==200){	           	              
        		$("#tokens").val(data.data);
      	 	  }
    	      
           }
       });
   }
   	   
   	function changePhone() {
		var country = $("#type").find("option:selected").val();
		if(country == null) {
			var htm='';
  		    htm +='<option value=" ">请选择</option>';
			return $("#country").html(htm);
		}
		
		 $.ajax({
            type: "get",
            url: "common/studyCountryList",
            dataType:"json",
            data:{type:country},
            success: function(data){    
           	
          	  if(data.code==200){	           	              
          		var htm='';
          		    htm +='<option value=" ">请选择</option>';
         		for (var i = 0; i < data.data.length; i++) {
	   				var bean = data.data;
	   				htm +='<option value="'+bean[i].id+'" code="'+bean[i].name+'">'+bean[i].name+'</option>';
  				}
         		$("#country").html(htm);
       	 	  }
     	      
            }
        });  
	}
   	
    //引入Plupload 、qiniu.js后
    var uploader = Qiniu.uploader({
        runtimes: 'html5,flash,html4', //上传模式,依次退化
        browse_button: 'pickfiles', //上传选择的点选按钮，**必需**
        //uptoken: 'pRyQPoTs_lqt02zxHGyriLUufn_RXvsDTkNQnkms:VMTl7m8fFl6ahK0d9ez7jHMdyHY=:eyJzY29wZSI6ImFpbGFpa2V2aWRlbyIsImRlYWRsaW5lIjoxNTE5ODE2OTk3fQ==',
        //uptoken: $("#tokens").val(),
         uptoken_url:'qiniu/uptoken', //Ajax请求upToken的Url，**强烈建议设置**（服务端提供）
        // uptoken : '', //若未指定uptoken_url,则必须指定 uptoken ,uptoken由其他程序生成
         unique_names: true, // 默认 false，key为文件名。若开启该选项，SDK为自动生成上传成功后的key（文件名）。
        // save_key: true, // 默认 false。若在服务端生成uptoken的上传策略中指定了 `sava_key`，则开启，SDK会忽略对key的处理
        domain: 'http://bbs.shituzx.com/', //bucket 域名，下载资源时用到，**必需**
        get_new_uptoken: true, //设置上传文件的时候是否每次都重新获取新的token
        container: 'container', //上传区域DOM ID，默认是browser_button的父元素，
        max_file_size: '2000mb', //最大文件体积限制
        flash_swf_url: 'Moxie.swf', //引入flash,相对路径
        max_retries: 3, //上传失败最大重试次数
        dragdrop: true, //开启可拖曳上传
        drop_element: 'container', //拖曳上传区域元素的ID，拖曳文件或文件夹后可触发上传
        chunk_size: '4mb', //分块上传时，每片的体积
        auto_start: false, //选择文件后自动上传，若关闭需要自己绑定事件触发上传
        filters : {//限制文件上传的格式
        	max_file_size : '2000mb',
            prevent_duplicates: true,
            //Specify what files to browse for
             mime_types: [
            {title : "Video files", extensions : "flv,mpg,mpeg,avi,wmv,mov,asf,rm,rmvb,mkv,m4v,mp4"}, //限定flv,mpg,mpeg,avi,wmv,mov,asf,rm,rmvb,mkv,m4v,mp4后缀格式上传
            ]
        },
        init: {
            'FilesAdded': function (up, files) {
                plupload.each(files, function (file) {
                    // 文件添加进队列后,处理相关的事情
                    console.log(file.name);
                    $("#text1").html("等待.....")
                });
            },
            'BeforeUpload': function (up, file) {
                // 每个文件上传前,处理相关的事情
            },
            'UploadProgress': function (up, file) {
                // 每个文件上传时,处理相关的事情
                $("#text1").html("上传中.....")
            },
            'FileUploaded': function (up, file, info) {
            	$("#text1").html("上传成功")
                console.log(up)
                console.log(file)
                console.log(info)
                // 每个文件上传成功后,处理相关的事情
                // 其中 info 是文件上传成功后，服务端返回的json，形式如
                // {
                // "hash": "Fh8xVqod2MQ1mocfI4S4KpRL6D98",
                // "key": "gogopher.jpg"
                // }
                // 参考http://developer.qiniu.com/docs/v6/api/overview/up/response/simple-response.html

                var domain = up.getOption('domain');
                var res = JSON.parse(info.response);
                var sourceLink = domain + res.key; //获取上传成功后的文件的Url
                console.log(res.key);
                $("#key").val(res.key);
                $("#url").val(sourceLink);
                $("#size").val(file.size);
            },
            'Error': function (up, err, errTip) {
                //上传出错时,处理相关的事情
                $("#text1").html("上传失败")
            },
            'UploadComplete': function () {
                //队列文件处理完毕后,处理相关的事情
            },
            /* 'Key': function (up, file) {
                // 若想在前端对每个文件的key进行个性化处理，可以配置该函数
                // 该配置必须要在 unique_names: false , save_key: false 时才生效

                var key = "12.png";
                // do something with key here
                return key
            }*/
        }
    });
    
    $("#uploadfiles").click(function(){
    	uploader.start();
    });
   
   	   
   	layui.use(['laydate','element','laypage','layer'], function(){
        $ = layui.jquery;//jquery
      laydate = layui.laydate;//日期插件
      lement = layui.element();//面包导航
      laypage = layui.laypage;//分页
      layer = layui.layer;//弹出层

      //以上模块根据需要引入
      var start = {
        min: '2000-01-01 00:00:00'
        ,max: '2099-06-16 23:59:59'
        ,istoday: false
        ,choose: function(datas){
          end.min = datas; //开始日选好后，重置结束日的最小日期
          end.start = datas //将结束日的初始值设定为开始日
        }
      };
      
      var end = {
        min: '2000-01-01 00:00:00'
        ,max: '2099-06-16 23:59:59'
        ,istoday: false
        ,choose: function(datas){
          start.max = datas; //结束日选好后，重置开始日的最大日期
        }
      };
      
      var end1 = {
    	        min: '2000-01-01 00:00:00'
    	        ,max: '2099-06-16 23:59:59'
    	        ,istoday: false
    	        ,choose: function(datas){
    	          start.max = datas; //结束日选好后，重置开始日的最大日期
    	        }
    	      };
      
      document.getElementById('LAY_demorange_s').onclick = function(){
        start.elem = this;
        laydate(start);
      }
      
    });
   	
        </script>
        <script type="text/javascript">
    	//实例化编辑器
    	var um = UM.getEditor('myEditor');
    	//失去焦点
    	um.addListener('blur',function(){
    	//判断是否有内容
        if(UM.getEditor('myEditor').hasContents()){
        	$("#infomationContent").val(UM.getEditor('myEditor').getContent());
        }
   	 	});
    	//获得焦点
    	um.addListener('focus',function(){
        
    	});
     	//营销管理
     	
	</script>
</body>
</html>